import { getCookie, downloadUtils, request, getQueryString } from '@inbiz/utils';

// 根据token获取用户信息
export async function checkAndCreateDocInfo(params: Upload.CreateDocInfoArgs) {
  let data: any = {
    module: 'RegionDocOperationApi',
    fun: 'CheckAndCreateDocInfo',
    ...params,
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: data,
  });
}

export async function UndoCreateFileByFileId(fileId: string) {
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: {
      module: 'WebClient',
      fun: 'UndoCreateFileByFileId',
      fileId: fileId,
    },
  });
}

export async function UndoCreateFileVer(fileId: string, fileVerId: string) {
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: {
      module: 'WebClient',
      fun: 'UndoCreateFileVer',
      fileId: fileId,
      fileVerId: fileVerId,
    },
  });
}

export async function GetFolderById(params: { folderId: number | string, code?: string | null }) {
  let args = {
    ...params,
    module: 'WebClient',
    fun: getQueryString('code') ? 'GetFolderPath' : 'GetFolderById',
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: args,
  });
}

export function GetFolderPropertyVerStrategy(folderId: number | string) {
  const args = {
    folderId,
    module: 'WebClient',
    fun: 'GetFolderPropertyVerStrategy',
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: args,
  });
}

// 根据文件夹id查询文件夹信息
export async function GetFolderInfoById(params: any) {
  const token = getCookie('token');
  return request(`/api/services/Folder/GetFolderInfoById?token=${token}`, {
    params,
  });
}

//获取流程策略
export const getProcessStrategy = (
  params: { fileIds?: string[]; folderIds?: string[] },
  processType: number,
) => {
  let args: any = {
    fileIds: params.fileIds?.join?.(','),
    folderIds: params.folderIds?.join?.(','),
    processType: processType,
  };
  return request(`/inbiz/api/services/WorkFlowDoc/IsProcessStrategy`, {
    method: 'GET',
    params: args,
  });
};

// 获取是否启用秒传
export const IsExistsHeadMd5 = (params: { headMd5: string, regionId: string | number }) => {
  const data = {
    ...params,
    module: 'UploadFileManager',
    fun: 'IsExistsHeadMd5',
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: data,
  });
}

// 获取ECM是否开启秒传配置
export const GetInstanceConfig = () => {
  const data = {
    module: 'SystemManager',
    fun: 'GetInstanceConfig',
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: data,
  });
}

// 获取当前用户限速配置
export const GetCurrentUserSpeedLimit = (userId: string | number) => {
  const token = getCookie('token');
  const data = {
    token,
    userId,
    module: 'SystemManager',
    fun: 'GetCurrentUserSpeedLimit'
  };
  return request('/WebCore', {
    requestType: 'form',
    method: 'POST',
    data: data,
  });
}